package com.cuijq.ms.strategy.v4;

import com.cuijq.ms.strategy.v4.impl.ConcurrentExternalSort;
import com.cuijq.ms.strategy.v4.impl.ExternalSort;
import com.cuijq.ms.strategy.v4.impl.MapReduceSort;
import com.cuijq.ms.strategy.v4.impl.QuickSort;
import java.io.File;

/**
 * @author by CuiJQ
 * @Classname Sorter
 * @Description Sorter Description
 * @Date 2021/5/29 9:06
 */
public class Sorter {

  private static final long GB = 1000 * 1000 * 1000;

  public void sortFile(String filePath) { // 省略校验逻辑
    File file = new File(filePath);
    long fileSize = file.length();
    ISortAlg sortAlg = null;
    if (fileSize < 6
        * GB) {
      // [0, 6GB)
      sortAlg=new QuickSort();
    } else if (fileSize < 10
        * GB) {
      // [6GB, 10GB)
      sortAlg=new ExternalSort();
    } else if (fileSize < 100
        * GB) {
      // [10GB, 100GB)
      sortAlg = new ConcurrentExternalSort();
    } else { // [100GB, ~)
      //
      sortAlg = new MapReduceSort();
    }
    sortAlg.sort(filePath);
  }
}
